using System;
using UnityEngine;

public class MapManager : MonoBehaviour
{
	[Serializable]
	public class EditorReferences
	{
		public MapParameters defaultMap;

		public MapParameters[] maps;
	}

	private static MapManager _instance;

	[SerializeField]
	public EditorReferences references = new EditorReferences();

	private MapParameters _currentMap;

	public static MapManager Instance
	{
		get
		{
			if (_instance == null)
			{
				_instance = UnityEngine.Object.FindObjectOfType<MapManager>();
				UnityEngine.Object.DontDestroyOnLoad(_instance.gameObject);
			}
			return _instance;
		}
	}

	public MapParameters CurrentMap
	{
		get
		{
			return _currentMap;
		}
		set
		{
			_currentMap = value;
		}
	}

	private void Awake()
	{
		if (_instance == null)
		{
			_instance = this;
			UnityEngine.Object.DontDestroyOnLoad(base.gameObject);
		}
		else if (_instance != this)
		{
			UnityEngine.Object.Destroy(base.gameObject);
		}
	}

	public void SetLastMap(string id)
	{
		_currentMap = GetMapWithId(id);
	}

	public MapParameters GetRandomMap()
	{
		return references.maps[UnityEngine.Random.Range(0, references.maps.Length)];
	}

	private MapParameters GetMapWithId(string id)
	{
		MapParameters[] maps = references.maps;
		foreach (MapParameters mapParameters in maps)
		{
			if (mapParameters.id == id)
			{
				return mapParameters;
			}
		}
		return references.defaultMap;
	}
}
